<template>
  <el-select :value="value"
             @input="setCurrentValue"
             :placeholder="placeholder"
             :filterable="filterable"
             :clearable="clearable"
             :multiple="multiple"
             :disabled="disabled">
    <slot></slot>
    <template v-for="item in options[type]">
      <el-option
        :key="item.value"
        :label="item.name"
        :value="item.value">
      </el-option>
    </template>
  </el-select>
</template>

<script>
import {mapState} from 'vuex'

export default {
  name: 'CSelect',
  data () {
    return {}
  },
  props: {
    value: {},
    type: {
      type: String,
      required: true
    },
    placeholder: String,
    disabled: Boolean,
    clearable: Boolean,
    multiple: Boolean,
    filterable: Boolean
  },
  computed: {
    ...mapState('options', ['options'])
  },
  created () {
    this.$service.options.setOptions(this.type)
  },
  methods: {
    setCurrentValue (value) {
      this.$emit('input', value)
      this.$emit('change', value)
    }
  }
}
</script>

<style>

</style>
